package com.gateway.plugin.resilience4j.config;

import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
import io.github.resilience4j.ratelimiter.RateLimiterConfig;
import io.github.resilience4j.timelimiter.TimeLimiterConfig;

/**
 * @program: api-gateway
 * @description:
 * @author: YuKai Fan
 * @create: 2025/2/24 09:43
 **/
public class Resilience4JConfig {

    /**
     * id.
     */
    private String id;

    /**
     * fallBackUri.
     */
    private String fallBackUri;

    /**
     * timeLimiterConfig.
     */
    private TimeLimiterConfig timeLimiterConfig;

    /**
     * circuitBreakerConfig.
     */
    private CircuitBreakerConfig circuitBreakerConfig;

    /**
     * rateLimiterConfig.
     */
    private RateLimiterConfig rateLimiterConfig;

    public Resilience4JConfig(String id, String fallBackUri, TimeLimiterConfig timeLimiterConfig, CircuitBreakerConfig circuitBreakerConfig, RateLimiterConfig rateLimiterConfig) {
        this.id = id;
        this.fallBackUri = fallBackUri;
        this.timeLimiterConfig = timeLimiterConfig;
        this.circuitBreakerConfig = circuitBreakerConfig;
        this.rateLimiterConfig = rateLimiterConfig;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFallBackUri() {
        return fallBackUri;
    }

    public void setFallBackUri(String fallBackUri) {
        this.fallBackUri = fallBackUri;
    }

    public TimeLimiterConfig getTimeLimiterConfig() {
        return timeLimiterConfig;
    }

    public void setTimeLimiterConfig(TimeLimiterConfig timeLimiterConfig) {
        this.timeLimiterConfig = timeLimiterConfig;
    }

    public CircuitBreakerConfig getCircuitBreakerConfig() {
        return circuitBreakerConfig;
    }

    public void setCircuitBreakerConfig(CircuitBreakerConfig circuitBreakerConfig) {
        this.circuitBreakerConfig = circuitBreakerConfig;
    }

    public RateLimiterConfig getRateLimiterConfig() {
        return rateLimiterConfig;
    }

    public void setRateLimiterConfig(RateLimiterConfig rateLimiterConfig) {
        this.rateLimiterConfig = rateLimiterConfig;
    }


    public static final class Builder {
        private String id;
        private String fallBackUri;
        private TimeLimiterConfig timeLimiterConfig;
        private CircuitBreakerConfig circuitBreakerConfig;
        private RateLimiterConfig rateLimiterConfig;

        private Builder() {
        }

        public static Builder builder() {
            return new Builder();
        }

        public Builder id(String id) {
            this.id = id;
            return this;
        }

        public Builder fallBackUri(String fallBackUri) {
            this.fallBackUri = fallBackUri;
            return this;
        }

        public Builder timeLimiterConfig(TimeLimiterConfig timeLimiterConfig) {
            this.timeLimiterConfig = timeLimiterConfig;
            return this;
        }

        public Builder circuitBreakerConfig(CircuitBreakerConfig circuitBreakerConfig) {
            this.circuitBreakerConfig = circuitBreakerConfig;
            return this;
        }

        public Builder rateLimiterConfig(RateLimiterConfig rateLimiterConfig) {
            this.rateLimiterConfig = rateLimiterConfig;
            return this;
        }

        public Resilience4JConfig build() {
            return new Resilience4JConfig(id, fallBackUri, timeLimiterConfig, circuitBreakerConfig, rateLimiterConfig);
        }
    }
}
